package com.yzh.map.teacher;

import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.*;

/**
 * 使用各种Map存储学号-学生映射
 */
public class TestMap2 {
    public static void main(String[] args) {
        //创建一个Map对象
        //Map<Integer,Student> map = new HashMap();
        //Map<Integer,Student> map = new LinkedHashMap();
        Map<Integer,Student> map = new TreeMap();
        //存入多个学号-学生映射
        Student stu1 = new Student(10,"zhangsan",23,98.0);
        Student stu4 = new Student(10,"zhangsan",23,98.0);
        Student stu2 = new Student(20,"lisi",24,100.0);
        Student stu3 = new Student(30,"wangwu",20,85.0);

        map.put(stu3.getId(),stu3);
        map.put(stu4.getId(),stu4);
        map.put(stu1.getId(),stu1);
        map.put(stu2.getId(),stu2);

        //map.clear();
        //map.containsKey(10);//true
        //map.containsValue(new Student(30,"wangwu",20,85.0));//true
        //map.replace(30,new Student(30,"zhaoliu",24,85.0));
        //map.remove(30);
        //System.out.println(map.isEmpty());
        System.out.println(map.size());
        System.out.println(map);
        System.out.println(map.get(30));

        //遍历:entrySet
        Set <Entry<Integer,Student>>entrySet = map.entrySet();
        for(Entry<Integer,Student> entry:entrySet){
            //System.out.println(entry.getKey()+"-------->"+entry.getValue());
            //System.out.println(entry.getValue());
            Student stu = entry.getValue();
            System.out.println(stu.getId()+":"+stu.getName());
        }


    }
}
